package com.shanxia.codec.cmd;

import com.shanxia.codec.ProtocolDataBase;
import com.shanxia.codec.enums.DecodeEnum;
import lombok.Data;

import java.util.Arrays;
import java.util.Objects;

import static com.shanxia.codec.CodeConstant.ONEBYTE_ADDRS;
import static com.shanxia.codec.Decoder.*;

/**
 * C -> S
 * 充电桩应答服务器下发升级文件大小指令
 */
@Data
public class Cmd1006 extends ProtocolDataBase {

    public static final int MIN_SIZE = 4;

    private int respSign;       // 响应标志

    public Cmd1006(){
        super.setCmd(1006);
    }

    public static Cmd1006 decodeFromBase(ProtocolDataBase protocolDataBase) {
        Cmd1006 cmd = new Cmd1006();
        cmd.copyDataFrom(protocolDataBase);
        byte[] dataField = protocolDataBase.getDataField();
        if (dataField.length < MIN_SIZE) {
            cmd.setResult(DecodeEnum.InvalidData);
            return cmd;
        }
        cmd.respSign = bytesToIntLittle(dataField, 0);
        return cmd;
    }

    @Override
    public String toString() {

        StringBuffer buffer = new StringBuffer();
        buffer.append("#cmd1006#").append("\n");
        buffer.append("响应标志:").append(respSign).append("\n");
        return buffer.toString();
    }
}
